package com.desk.api.service;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.desk.api.constant.LearnStatus;
import com.desk.api.emtity.Learn;
import com.desk.api.mapper.LearnMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Service
public class LearnServiceImpl extends ServiceImpl<LearnMapper, Learn> implements LearnService {
  @Override
  public void reportData(String msg) {
    JSONObject jsonObject = JSONUtil.parseObj(msg);
    Integer status = jsonObject.getInt("status");
    Learn learn = new Learn();
    LearnStatus.getByCode(status).ifPresent(learn::setStatus);
    String time = jsonObject.getStr("time");
    learn.setTime(LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    save(learn);
  }
}
